//
//  AudioContentTableViewCell.m
//  MIDI
//
//  Created by 王禹丞 on 15/11/19.
//  Copyright © 2015年 QXSX. All rights reserved.
//

#import "AudioContentTableViewCell.h"

#import "GradingTestSongDetailModel.h"

@interface AudioContentTableViewCell()

@property (weak, nonatomic) IBOutlet UILabel *titelLabel;

@property (weak, nonatomic) IBOutlet UIButton *downBtn;

@property (weak, nonatomic) IBOutlet UIButton *shareBtn;

@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@property (weak, nonatomic) IBOutlet UILabel *isDownloadLabel;



@end


@implementation AudioContentTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"AudioContentTableViewCell";
    AudioContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        
        cell = [[[NSBundle mainBundle] loadNibNamed:ID owner:nil options:nil]firstObject];
        
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    
    return cell;
}

-(void)awakeFromNib{

       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isFinishDownLoad) name:@"isFinishDownLoad" object:nil];
   
        [self.shareBtn addTarget:self action:@selector(shareBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)shareBtnOnClick{
    
    
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"shareToWeChat" object:nil];
    
    
    
}
- (void)isFinishDownLoad{

    
    _downBtn.hidden = YES;
    
    _isDownloadLabel.hidden = NO;


}


-(void)setSongModel:(GradingTestSongDetailModel *)songModel{

    
    _songModel = songModel;
    
    _titelLabel.text = _songModel.song_name;

    _contentLabel.text = _songModel.song_brief;
    
    if (_songModel.isDownLoad) {
        
        [self isFinishDownLoad];
        
        return;
    }
    
    [self.downBtn addTarget:self action:@selector(beginDownLoad) forControlEvents:UIControlEventTouchUpInside];
    
    //设置行距
    [self setLine];

}

- (void)beginDownLoad{


    if ([self.delegate respondsToSelector:@selector(downLoadBtnOnClick)]) {
        
        [self.delegate downLoadBtnOnClick];
        
    }
}

-(void)setLine
{
    NSMutableAttributedString *attributedString = [[ NSMutableAttributedString alloc] initWithString:self.contentLabel.text];
    
    NSMutableParagraphStyle *paragraphStyle = [[ NSMutableParagraphStyle alloc ] init];
    
    paragraphStyle.alignment = NSTextAlignmentLeft;
    
    paragraphStyle.lineSpacing = 5; //行距
    
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.contentLabel.text length])];
    
    self.contentLabel.attributedText = attributedString;
    
    [self.contentLabel sizeToFit];
}


@end
